<!DOCTYPE html>
<html>
<head>
    {include file='public/meta'/}
    <link rel="stylesheet" type="text/css" href="__STATIC_URL__/static/css/bootstrap-datetimepicker.css"/>

    <link rel="stylesheet" type="text/css" href="__STATIC_URL__/static/css/setyxhd.css?v=5"/>
    <link rel="stylesheet" type="text/css" href="__STATIC_URL__/static/fonts/css/font-awesome.css?v=3"/>
    <link rel="stylesheet" href="__STATIC_URL__/static/css/bootstrapSwitch.css">
    <script src="__STATIC_URL__/static/js/bootstrap-datetimepicker.js" type="text/javascript" charset="utf-8"></script>
    <script src="__STATIC_URL__/static/js/bootstrapSwitch.js"></script>
    <style>

    </style>
</head>
<body>
{include file='public/header'/}
<!------------------导航-------------------------->
<section>
    {include file='public/left'/}
    <!--------------------------主要内容区域------------------------------------->
    <div class="content">
        <ol class="breadcrumb">
            <li>当前位置是&nbsp;:</li>
            <li><a href="javascript:history.back();">营销工具</a></li>
            <li><a href="javascript:history.back(-1)">活动营销</a></li>

            <li class="active" style="color: #02b87f;">生日关怀设置</li>
        </ol>
        <div class="panel mgl15 mgr15">
            <div class="panel-body ">
                <!--路径导航-->
                <div class="panel panel-default ng-scope " style="    border: 1px solid #ddd;">
                    <div class="panel-heading">
                        生日关怀规则列表
                    </div>

                    <div class="panel-body">
                        <table class="table table-bordered">
                            <thead>
                            <tr>
                                <td>活动名称</td>
                                <td>活动时间</td>
                                <td>通知内容</td>
                                <td>提前天数</td>
                                <td>发送时间</td>

                                <td>赠送卡券</td>
                                <td>赠送积分</td>
                                <td class="text-center">操作</td>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name="carelist" id="vor"}
                            <tr class="ng-scope">
                                <td>{$vor.title}</td>
                                <td>{$vor.times}</td>
                                <td>{$vor.remark}</td>

                                <td>{$vor['advance_day']}</td>
                                <td>{$vor.notice_time}</td>

                                <td>{$vor.zs_card_info}</td>
                                <td>{$vor.bonus}</td>
                                <td>
                                    {if
                                    condition="$vor['statu']=='1' "}
                                    <a class="btn-link" href="javascript:;" data-id="{$vor['id']}" onclick="setsrcarestatu(this);" >已开启</a>
                                    {else/}
                                    <a class="btn-link" href="javascript:;" data-id="{$vor['id']}" onclick="setsrcarestatu(this);" style="color:#FF3030">已关闭</a>
                                    {/if}
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                        </table>
                    </div>
                </div>
                <div>


                    <div class="panel panel-default ng-scope c_content">

                        <form action="" method="post"  id="formcate">

                            <div class="headings gengduoxian">
                                <i class="infoLine"></i>生日关怀设置规则 <span class="note-inf">带<a style="color:red;"> * </a>为必填项</span>
                            </div>

                            <div class="panel-body">
                                <!--<div class="alert alert-success"-->
                                     <!--style="background-color: rgba(204, 228, 223, 0.3);margin-top: 10px;margin-bottom: 20px;">-->
                                    <!--<strong>-->
                                        <!--<i class="ti-info-alt"></i>-->
                                    <!--</strong>-->
                                    <!--<p></p>-->
                                    <!--<p></p>-->
                                <!--</div>-->
                                <div class="row">
                                    <div class="col-sm-6">
                                        <div class="form-horizontal" data-layout="horizontal">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label"><span class="red-xing-rs"></span>活动名称：</label>
                                                <div class="col-sm-10">
                                                    <input type="hidden" id="cid" value="{$info['id']}">
                                                    <input type="text" name="title" id="title" class="form-control"
                                                           maxlength="32" placeholder="请输入活动名称" value="{$info['title']}" onchange="tex('title','text-title','8');"/>
                                                    <div class="r-message text-danger" id="text-title"></div>
                                                </div>
                                            </div>
                                        </div>


                                            <div class="form-horizontal" data-label="活动时间"
                                                 data-layout="horizontal">
                                                <div class="form-group">
                                                    <label class="col-sm-2 control-label"><span class="red-xing-rs"></span>活动时间：</label>
                                                    <div class="col-sm-10">
                                                        <div class=" w60">
                                                            <input type="text" name="times" class="form-control data_ipt" value="{$info['times']}" placeholder="请选择开始时间-结束时间" disabled id="starttime">

                                                        </div>
                                                        <div class="checkbox checkbox-primary permanent"
                                                             style="left: 41px;top: 4px;display: inline-block;">
                                                            <input type="hidden" name="time_type"  value="{$info['time_type']}" id="lasting">
                                                            <input id="permanent_ck" type="checkbox"
                                                                   class="autoDelayFlag" {if condition="$info['time_type'] eq 'lasting'"}checked{/if}  >
                                                            <label for="permanent_ck">永久有效</label>
                                                        </div>
                                                    </div>

                                                </div>
                                            </div>



                                        <div class="form-horizontal" id="a_url">
                                            <div class="form-horizontal" data-label="通知内容"
                                                 data-layout="horizontal">
                                                <div class="form-group">
                                                    <label class="col-sm-2 control-label"><span class="red-xing-rs"></span>通知内容：</label>
                                                    <div class="col-sm-10">
                                                        <input type="text" name="remark" class="form-control"
                                                               id="remark" maxlength="32" placeholder="请输入通知内容，例如生日快乐"
                                                               value="{$info['remark']}" onchange="tex('remark','text-danger','20');">
                                                        <div class="r-message text-danger" id="text-danger"></div>
                                                    </div>
                                                </div>
                                            </div>

                                        </div>
                                        <div class="form-horizontal" data-layout="horizontal">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label"><span class="red-xing-rs"></span>提前通知天数：</label>
                                                <div class="col-sm-10">

                                                    <input type="number" name="advance_day" id="advance_day"
                                                           class="form-control" min="0" max="100000000" placeholder=""
                                                           value="{$info['advance_day']}"
                                                           onkeyup="this.value=this.value.replace(/\D/g,&#39;&#39;)" style="width:80px;display: inline-block;"/> 天
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-horizontal" data-layout="horizontal">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label"><span class="red-xing-rs"></span>祝福通知时间：</label>
                                                <div class="col-sm-10">
                                                    <select name="notice_time" id="notice_time" class="form-control" style="width:110px;">
                                                        <option value="{$info['notice_time']}" >{$info['notice_time']}</option>
                                                        <option value="01:00:00" >01:00</option>
                                                        <option value="02:00:00" >02:00</option>
                                                        <option value="03:00:00" >03:00</option>
                                                        <option value="04:00:00" >04:00</option>
                                                        <option value="05:00:00" >05:00</option>
                                                        <option value="06:00:00" >06:00</option>
                                                        <option value="07:00:00">07:00</option>
                                                        <option value="08:00:00" >08:00</option>
                                                        <option value="09:00:00">09:00</option>
                                                        <option value="10:00:00">10:00</option>
                                                        <option value="11:00:00" >11:00</option>
                                                        <option value="12:00:00">12:00</option>
                                                        <option value="13:00:00" >13:00</option>
                                                        <option value="14:00:00" >14:00</option>
                                                        <option value="15:00:00" >15:00</option>
                                                        <option value="16:00:00" >16:00</option>
                                                        <option value="17:00:00">17:00</option>
                                                        <option value="18:00:00" >18:00</option>
                                                        <option value="19:00:00" >19:00</option>
                                                        <option value="20:00:00" >20:00</option>
                                                        <option value="21:00:00">21:00</option>
                                                        <option value="22:00:00" >22:00</option>
                                                        <option value="23:00:00" >23:00</option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-horizontal" data-layout="horizontal">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label"><span class="red-xing-rs"></span>适用等级：</label>
                                                <div class="col-sm-10">
                                                    <a href="javascript:void(0);" id="selectLevel"
                                                       style=" line-height: 31px;">
                                                        <span id="select_text" style=" margin-left: 30px; ">已选择 <span
                                                                id="LevelCount">0</span> 种等级</span> </a>

                                                    <input type="hidden" class="form-control " id="memberLevelIds"
                                                           name="memberLevelIds" value="{$info['memberLevelIds']}">
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-horizontal" data-layout="horizontal">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label"><span class="red-xing-rs"></span>活动奖品：</label>
                                                <div class="col-sm-10">

                                                    <div style=" margin-top:3px;">
                                                        <div class="checkbox checkbox-info checkbox-inline prize">
                                                            <input type="hidden" id="isbonus"  value="{$info['is_bonus']}" name="is_bonus">
                                                            <input type="checkbox" id="bonus" {if condition="$info['is_bonus'] eq '2'"}checked{/if} class="gift-input" >
                                                            <label for="bonus"> 赠送积分 </label>
                                                            <span class="container" style="display:none;">
    							                                <div class="col-md-6 pannel charge-rule-box"
                                                                     style="float:none;margin-top:10px;margin-left: -22px;width: 400px;">

                                                                    <div style="margin-top:10px;" class="gift-record">

    											                          <input type="number"
                                                                                 class="form-control prize-gift" min="1"
                                                                                 onkeyup="this.value=this.value.replace(/\D/g,&#39;&#39;)"
                                                                                 style="width: 80px;margin-left: 3px;display: inline-block;"
                                                                                 placeholder="请填写" name="bonus" value="{$info['bonus']}">
                                                                          <span style=" margin-left: 5px;line-height:38px;">积分</span>
                                                                          <a href="javascript:void(0);"
                                                                             class="del-charge-btn"
                                                                             style="display:none;"><i
                                                                                  class="icon-close"></i>
                                                                          </a>
                                                                    </div>
    							                				</div>
    								                         </span>
                                                        </div>
                                                        <div class="checkbox checkbox-info checkbox-inline prize">
                                                            <input type="hidden" id="iscards"  value="{$info['is_bonus']}"  name="is_cards">

                                                            <input type="checkbox" id="cards" class="gift-input"  {if condition="$info['is_cards'] eq '2'"}checked{/if}>
                                                            <label for="cards"> 赠送优惠券 </label>
                                                            <span class="container " style="display:none;" coupontype="0" >

                                                                <div class="col-xs-10 col-sm-10 col-md-10 form1" >

                                            <a href="javascript:;"  data-counts="1" id="datacount" style="margin-top: 6px;color: #2db7f5; font-size: 13px;">添加赠送</a>
                                        </div>

                                                            </span>
                                                        </div>


                                                    </div>

                                                </div>
                                            </div>
                                        </div>


                                    </div>
                                </div>
                                <div class="alert alert-danger"
                                     style="margin:0;">每类规则只能同时存在一个
                                </div>
                            </div>
                            <div class="panel-footer">
                                <button class="btn btn-success" type="button" onclick="btn();">保存</button>
                            </div>
                        </form>
                    </div>

                </div>
            </div>
        </div>
        {include file='public/footer'/}
    </div>
</section>
<div class="modal fade club-modal" id="levelModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">会员等级</h4>
            </div>
            <div class="modal-body" style="padding: 0;">
                <div style=" padding: 0; overflow-y: auto; overflow-x: hidden; max-height: 700px; ">
                    <div style="line-height: 40px;color: #5d9cec;">
                        <span id="level_select_text" style=" margin-left: 30px; ">已选择 <span
                                id="selectLevelCount">0</span> 种等级</span>
                    </div>
                    <table class="table level-table">
                        <tbody>
                        <tr class="th">
                            <th style=" width: 20px; ">
                                <div class="checkbox checkbox-primary">
                                    <input id="level_checkbox_all" type="checkbox" class="select-all-level">
                                    <label for="level_checkbox_all"></label>
                                </div>
                            </th>
                            <th>等级名称</th>
                        </tr>

                        {volist name="ranklist" id="vo"}
                        <tr class="level-cell">
                            <td>
                                <div class="checkbox checkbox-primary">
                                    <input id="checkbox_1" type="checkbox" class="single-level" data-id="{$vo['live']}">
                                    <label for="checkbox_1"></label>
                                </div>
                            </td>
                            <td>{$vo['live_title']}</td>
                        </tr>
                        {/volist}


                        </tbody>
                    </table>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    取消
                </button>
                <button type="button" class="btn btn-primary confirm">
                    确定
                </button>
            </div>
        </div>
    </div>
</div>
<script src="__STATIC_URL__/static/laydate/laydate.js"></script>
<script>
    $(function(){
        var id=$("#cid").val();
        $.ajax({
            url: "{:url('marke/getsrcarecardslist')}",
            type: "post",
            data: {id:id},
            success: function (data) {
                console.log(1, data);
                var text = data;
                var html8=""
                for(var i=0; i<text.length; i++){
                    // console.log(text[i].card_id);
                    if(text[i].title==null){
                        html8=""
                    }else{
                        var html8 ='                        <div class="col-xs-12 col-sm-12 col-md-12 addcord" >\n' +
                            '                            <div class="gift-record">\n' +
                            '                                <select name="cardlist[zs_card_id][]"  class="form-control" >\n' +
                            '                                    <option value="'+text[i].card_id+'" data-title="'+text[i].title+' "data-limit="'+text[i].get_limit+'">'+text[i].title+'  ( 最大可选卡券数量为'+text[i].get_limit+')</option>\n' +
                            '                                     </select>\n' +
                            '                                <input type="number" class="form-control" min="1" placeholder="请填写" value="'+text[i].zs_no+'" name="cardlist[zs_no][]">\n' +
                            '                            </div>\n' +
                            '                             <a href="javascript:;" onclick="delsel(this)">删除</a>\n' +
                            '                    </div>';
                    }

                    $('.form1').append(html8)
                }

            }
        });
        $.ajax({
            url: "{:url('cards/getfreecard')}",
            type:"post",
            data: {
            },
            success: function (data) {
                console.log(1,data);
                var text =data.data;
                //console.log(text);
                var option2="";
                for(var i=0; i<text.length; i++){
                    // console.log(text[i].card_id);

                    option2 +='<option value="'+text[i].card_id+'" data-title="'+text[i].title+' "data-limit="'+text[i].get_limit+'">'+text[i].title+'  ( 最大可选卡券数量为'+text[i].get_limit+' )</option>\n'

                }
                $('#sel1').find("select").append(option2);
                $("#opt").change(function(){

                    limit=parseInt($("#sel1").find("option:selected").attr("data-limit"));
                    var nu=parseInt($("#num").val());

                    $("#num").attr("max",limit);





                });

                $("#datacount").click(function(){


                    datacount=$(this).attr('data-counts');
                    get_limit=parseInt($("#sel"+datacount).find("option:selected").attr("data-limit"));
                    num=parseInt($("#sel"+datacount).find("input").val());
                    val=$("#sel"+datacount).find("option:selected").val();
                    if( $("#sel"+datacount).find("option:selected").val()==""){
                        alert("卡券选项不能为空");
                        return;
                    }
                    else if(num>get_limit){
                        console.log(num,get_limit);
                        console.log(num>get_limit);
                        alert("你选择的卡券数量超过了该卡券的领取数量!");
                        return;
                    }
                    else{

                        datacount2=parseInt(datacount)+1;
                        $(this).attr('data-counts',datacount2);
                        var html1 ='                        <div class="col-xs-12 col-sm-12 col-md-12 addcord" >\n' +
                            '                            <div class="gift-record"id="sel'+datacount2+'">\n' +
                            '                                <select name="cardlist[zs_card_id][]"  class="form-control" >\n' +
                            '                                    <option value="" selected="selected">--请选择--</option>\n' ;

                        var html3= '                                </select>\n' +
                            '                                <input type="number" class="form-control" min="1" placeholder="请填写" value="1" name="cardlist[zs_no][]">\n' +
                            '                            </div>\n' +
                            '                             <a href="javascript:;" onclick="delsel(this)">删除</a>\n' +
                            '                    </div>';

                        $('.form1').append(html1+option2+html3);

                        $("#sel"+datacount2).find("select").change(function(){

                            limit=$("#sel"+datacount2).find("option:selected").attr("data-limit");
                            $("#sel"+datacount2).find("input").attr("max",limit);



                        });

                    }




                })
            }
        })


    })
</script>
<script>

    function delsel(obj){
//
        $(obj).parent().remove();


    }

</script>
<script>

</script>
<script>
    laydate.render({
        elem: '#starttime',
        type: 'datetime',
        range: '-',

        change: function (value, date, endDate) { //监听日期被切换


        }
    });
</script>
<script>
    $(function(){
        var permanent_ck="{$info['time_type']}";
        if(permanent_ck==""){
            $("#permanent_ck").prop("checked", true)
        }
        var is_bonus="{$info['is_bonus']}";
        var $bonus = $("#bonus").parent().find(".container");
        var is_cards="{$info['is_cards']}";
        var $cards = $("#cards").parent().find(".container");
        if(is_bonus==2){
            $bonus.show();
        }
        if(is_cards==2){
            $cards.show();
        }
        var levelIds = $("#memberLevelIds").val();

        $(".single-level").removeAttr("checked");
        $("#level_checkbox_all").removeAttr("checked");
        $.each(levelIds.split(","), function (i, n) {
            var $cell = $(".single-level[data-id='" + n + "']");
            if ($cell != null) {
                $cell.attr("checked", true);
                $cell.prop("checked", true);
            }
        });
        if ($(".single-level:not(:checked)").length == 0) {
            $("#level_checkbox_all").attr("checked", true);
            $("#level_checkbox_all").prop("checked", true);
        }
        if ($(".single-level:checked").length == 0) {
            $("#level_checkbox_all").removeAttr("checked");
        }
        $("#LevelCount").text($(".single-level:checked").length);
    });
        // 永久有效
        $(".permanent").click(function (event) {
            event.stopPropagation();
            if ($("#permanent_ck:checked").length == 0) {
                $(".data_ipt").removeAttr("disabled");
                $("#lasting").val("range");
            } else {
                $(".data_ipt").val('');
                $(".data_ipt").attr("disabled", "disabled");
                $("#lasting").val("lasting");
            }
        })

        // 点击选择等级
        $("#selectLevel").click(function () {
            var levelIds = $("#memberLevelIds").val();

            $(".single-level").removeAttr("checked");
            $("#level_checkbox_all").removeAttr("checked");
            $.each(levelIds.split(","), function (i, n) {
                var $cell = $(".single-level[data-id='" + n + "']");
                if ($cell != null) {
                    $cell.attr("checked", true);
                    $cell.prop("checked", true);
                }
            });
            if ($(".single-level:not(:checked)").length == 0) {
                $("#level_checkbox_all").attr("checked", true);
                $("#level_checkbox_all").prop("checked", true);
            }
            if ($(".single-level:checked").length == 0) {
                $("#level_checkbox_all").removeAttr("checked");
            }
            $("#selectLevelCount").text($(".single-level:checked").length);

            $("#levelModal").modal("show");
        });
        // 等级弹框确定按钮
        $("#levelModal .confirm").click(function () {
            var idarray = new Array();
            $(".single-level:checked").each(function () {
                idarray.push($(this).attr("data-id"));
            });
            if (idarray.length == 0) {
                layer.msg('至少选择一个会员等级');
                return;
            }

            $("#memberLevelIds").val(idarray.join(","));

            $("#selectLevel").text($("#level_select_text").text());
            $("#levelModal").modal("hide");
        });
        // 等级弹框全选按钮
        $("#level_checkbox_all").change(function () {
            if ($(this).is(":checked")) {
                $(".single-level").attr("checked", true);
                $(".single-level").prop("checked", true);
            } else {
                $(".single-level").removeAttr("checked");
            }
            $("#selectLevelCount").text($(".single-level:checked").length);
        });
        // 等级弹框单个门店复选框
        $(".single-level").change(function () {
            if ($(".single-level:checked").length == $(".single-level").length) {
                $("#checkbox_all").attr("checked", true);
                $("#checkbox_all").prop("checked", true);
            } else {
                $("#checkbox_all").removeAttr("checked");
            }
            $("#selectLevelCount").text($(".single-level:checked").length);
        });
        //奖品复选框点击事件
        $(".gift-input").change(function () {
            var $container = $(this).parent().find(".container");
            var inputs=$(this).siblings("input");
            if ($(this).is(":checked")) {
                $container.show();
                inputs.val("2");
            } else {
                $container.hide();
                inputs.val("1");
            }
        });




    //判断纯数字
    function isNumber(num) {
        var pat = new RegExp('^[0-9]+$');
        return pat.test(num)
    }


</script>
<script>


    function tex(idq,tex,num){
        console.log(idq,tex,num)
        $("#"+tex).text("还可以输入" + (num - $("#"+idq).val().length) + "个字");


        if ( $("#"+idq).val().length > num) {
            $("#"+idq).val( $("#"+idq).val().substring(0, num));
        }
        $("#"+tex).text("还可以输入" + (num -  $("#"+idq).val().length) + "个字");
        var val=$("#"+idq).val();
        $("."+idq).html(val)
        $("."+idq).val(val)
        // console.log($("#"+idq).val());
    }


</script>
<script>
    function btn(){
        var title=$("#title").val();
        var starttime=$("#starttime").val();
        var remark=$("#remark").val();

        var advance_day=$("#advance_day").val();
        var memberLevelIds=$("#memberLevelIds").val();

        if(title==""){
            layer.msg('请填写活动名称！');
            return false;
        }
        if ($('#permanent_ck').prop("checked")==false) {
            if(starttime==""){
                layer.msg('请填写活动时间！');
                return false;
            }
        }
        if(remark==""){
            layer.msg('请填写通知内容！');
            return false;
        }
        if(advance_day==""){
            layer.msg('请填写提前通知天数！');
            return false;
        }
        if(advance_day<1){
            layer.msg('提前通知天数最少一天！');
            return false;
        }
        if(notice_time==""){
            layer.msg('请填写祝福通知时间！');
            return false;
        }
        // if(memberLevelIds==""){
        //     layer.msg('请选择适用等级！');
        //     return false;
        // }

        if ($('#bonus').prop("checked")==false&&$('#cards').prop("checked")==false) {

                layer.msg('请选择活动奖品！');
                return false;

        }
        var prize=$('.prize-gift').val();
        if ($('#bonus').prop("checked")==true) {
            if(prize==""){
                layer.msg('请填写赠送积分！');
                return false;
            }


        }
        var items = document.getElementsByTagName('select'),
            len = items.length,
            i = 0,
            valMap = {},
            sel,
            val;

        // 遍历并保存各个下拉列表的值于valMap
        for(; i < len; i++){
            sel = items[i];
            val = sel.options[sel.selectedIndex].value;

            // 没有相同的取值时保存该值，否则返回false
            if(!valMap[val]){
                valMap[val] = 1;
            }else{
                alert('请删除重复的卡券！');
                return false;
            }

        }



        $.ajax({
            url: "{:url('')}",
            type: "post",
            data: $("#formcate").serialize(),
            success: function (data) {
                console.log(data);
                if(data.code==0){
                    layer.msg(data.message);
                    setTimeout(function(){
                      window.location.reload();

                    },1000)
                }else{
                    layer.msg(data.message);
                }
            }
        })
    }
</script>
<script>
    function setsrcarestatu(obj) {
        var id = $(obj).attr("data-id");
        console.log(id);
        $.ajax({
            url: "{:url('marke/srcarestatu')}",
            type: "post",
            data: {
                id: id
            },
            success: function (data) {
                // console.log(11, data);
                if(data.code=="0"){
                    window.location.reload();
                }else{
                    layer.alert(data.message);
                }


            }
        })

    }
</script>
</body>

</html>
